package com.fowo.api.sys.entity;

import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
import com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.Setter;

import java.io.Serializable;
import java.util.List;

/**
 * 系统导入模版
 * @author yl_ls
 */
@EqualsAndHashCode(callSuper = true)
@Data
@Schema(title = "系统导入模版")
@TableName(value = "sys_import_template", autoResultMap = true)
public class SysImportTemplate extends SysBase implements Serializable {
    /**
     * 导入类型模版常量
     */
    public static final int TYPE_IMPORT = 1;

    /**
     * 导出类型模版常量
     */
    public static final int TYPE_EXPORT = 2;

    /**
     * 模型类型
     */
    private Integer type;
    /**
     * 所属对象
     */
    private String objectName;

    /**
     * 标题
     */
    private String title;

    /**
     * 设置
     */
    @TableField(typeHandler = JacksonTypeHandler.class)
    private Setting setting;

    private Long createUser;
    private Long lastUpdateUser;

    @Getter
    @Setter
    public static class Setting implements Serializable {

        /**
         * Excel 列信息
         */
        private List<ExcelColumn> excelColumns;

        /**
         * 列对应信息
         */
        private List<Mapping> mappings;
    }


    @Getter
    @Setter
    public static class ExcelColumn implements Serializable {
        private String key;
        private String name;
    }


    @Getter
    @Setter
    public static class Mapping implements Serializable {
        /**
         * 目标字段名
         */
        private String field;

        /**
         * 导入数据来源 Excel 列名，如果是多个先合并再处理
         */
        private List<String> excelColumnNames;

        /**
         * 导入时是否重建值
         * <ul>
         *     <li>对于序列号字段，会请求新的序列号</li>
         * </ul>
         */
        private Boolean needRecreate;
    }
}
